<?php
session_start();
require_once 'include/db.php';
require_once 'include/userClass.php';
require_once 'include/adminClass.php';

$title="Administrator statisikk";
include 'include/header.php';

if($user -> userLoggedOn() && $user->isUserAdmin()) {
	// IF user is beeing blocked:
    if(isset($_POST['userrep'])) {
		$action = $admin->blockUser($_POST['userrep']);
		unset($_POST);
	}
	if(isset($_POST['userunblock'])) {
		$action = $admin->unBlockUser($_POST['userunblock']);
		unset($_POST);
	}
	
	echo "<div id='content'>";
	// If admin is showing users with most blocked posts
	if(isset($_GET['stat']) && $_GET['stat']=='block') {
        echo "<h2>Brukere med flest blokkerte innlegg</h2>";
		if(isset($action)) {
			echo "<h4>".$action."</h4>";
		}
        $admin->getTopBlockedPostAuthors(10);
    }
	// If admin is showing reported users
    elseif(isset($_GET['stat']) && $_GET['stat']=='report') {
        echo "<h2>Rapporterte brukere</h2>";
		if(isset($action)) {
			echo "<h4>".$action."</h4>";
		}
        $admin->getReportedAuthors();
    }
	elseif(isset($_GET['stat']) && $_GET['stat']=='unblock') {
        echo "<h2>Blokkerte brukere</h2>";
		if(isset($action)) {
			echo "<h4>".$action."</h4>";
		}
        $admin->getBlockedUsers();
    }
    else {
       echo "<h2>Velg oversikt</h2>";
       echo "<form id='adminform' name='statform' action='adminStat.php' method='get'>\n
                <input type='hidden' name='usrName' value='".$_GET['usrName']."' />
                <select name='stat'>
                    <option value='block'>Bukere med flest blokkerte innlegg</option>
                    <option value='report'>Rapporterte brukere</option>
					<option value='unblock'>Blokkerte brukere</option>
                </select>
                <input type='submit' value='Velg'>
            </form>";
    }
    
    echo"</div>\n
    <div id='side'>";
        $user -> showUserInfo($user -> getUserInfo(NULL));
        echo "<a class='button' href='adminStat.php?usrName=".$user->userName."' title='Statistikk'>Brukeroversikt</a><br/>\n
			<a class='button' href='newAdmin.php?usrName=".$user->userName."' title='Ny admin'>Ny administrator</a><br/>
			<a class='button' href='displayUsr.php?usrName=".$user->userName."&own=true' title='Min blogg'>Min blogg</a><br/>
            <a class='button' href='newPost.php?usrName=".$user->userName."' title='Nytt innlegg'><img class='icon' src='include/img/Edit.png' />Nytt innlegg</a><br/>\n
			<a class='button' href='editUser.php' title='Rediger profil'><img class='icon' src='include/img/Wheel.png' />Rediger profil</a>";
    echo "</div>";
}
else { ?>
    <div id="content">
        <h2>Oooops!</h2>
        <p>Du har ikke tilgang på denne siden...</p>
    </div>
<?php }

include 'include/footer.php';

?>